<?php

/**
 * @Project NUKEVIET 3.x - GETNEWS
 * @Author ĐẶNG ĐÌNH TỨ (dlinhvan@gmail.com)
 * @Copyright (C) 2010 webdep24.com All rights reserved
 * @Createdate 10/08/2012 08:00
 */

if( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );

$arr_gio = array(
	1345050000,
	1345053600,
	1345057200,
	1345060800,
	1345064400,
	1345068000,
	1345071600,
	1345075200,
	1345078800,
	1345082400,
	1345086000,
	1345089600,
	1345093200,
	1345096800,
	1345100400,
	1345104000,
	1345107600,
	1345111200,
	1345114800,
	1345118400,
	1345122000,
	1345125600,
	1345129200,
	1345132800 );
$arr_phut = array(
	60,
	180,
	300,
	420,
	540,
	660,
	780,
	900,
	1020,
	1140,
	1260,
	1380,
	1500,
	1620,
	1740,
	1860,
	1980,
	2100,
	2220,
	2340,
	2460,
	2580,
	2700,
	2820,
	2940,
	3060,
	3180,
	3300,
	3420,
	3540,
	3660,
	3780,
	3900,
	4020,
	4140,
	4260,
	4380,
	4500,
	4620,
	4740,
	4860,
	4980,
	5100,
	5220,
	5340,
	5460,
	5580,
	5700,
	5820,
	5940,
	6060,
	6180,
	6300,
	6420,
	6540,
	6660,
	6780,
	6900,
	7020,
	7140 );
$arr_phut1 = array(
	120,
	180,
	240,
	300,
	360,
	420,
	480,
	540,
	600,
	660,
	720,
	780,
	840,
	900,
	960,
	1020,
	1080,
	1140,
	1200,
	1260,
	1320,
	1380,
	1440,
	1500,
	1560,
	1620,
	1680,
	1740,
	1800,
	1860,
	1920,
	1980,
	2040,
	2100,
	2160,
	2220,
	2280,
	2340,
	2400,
	2460,
	2520,
	2580,
	2640,
	2700,
	2760,
	2820,
	2880,
	2940,
	3000,
	3060,
	3120,
	3180,
	3240,
	3300,
	3360,
	3420,
	3480,
	3540 );
$arr_phut2 = array(
	240,
	360,
	480,
	600,
	720,
	840,
	960,
	1080,
	1200,
	1320,
	1440,
	1560,
	1680,
	1800,
	1920,
	2040,
	2160,
	2280,
	2400,
	2520,
	2640,
	2760,
	2880,
	3000,
	3120,
	3240,
	3360,
	3480,
	3600,
	3720,
	3840,
	3960,
	4080,
	4200,
	4320,
	4440,
	4560,
	4680,
	4800,
	4920,
	5040,
	5160,
	5280,
	5400,
	5520,
	5640,
	5760,
	5880,
	6000,
	6120,
	6240,
	6360,
	6480,
	6600,
	6720,
	6840,
	6960,
	7080 );

$query = "SELECT `id`,`start_time`,`interval`,`run_file` FROM `" . NV_CRONJOBS_GLOBALTABLE . "` WHERE run_file LIKE '%dangdinhtu%' AND act=1 ORDER BY `is_sys` DESC";
$result = $db->sql_query( $query );
$i = 2;
$a = 2;
while( $row = $db->sql_fetchrow( $result ) )
{

	$rand_keys = array_rand( $arr_gio, $i );
	$keys = array_rand( $arr_phut, $a );
	$time = $arr_gio[$rand_keys[1]];
	$giay = $arr_phut[$keys[1]];
	$start_time = $time + $giay;
	if( $row['interval'] >= 20 and $row['interval'] = 30 )
	{
		$interval = rand( 20, 30 );
	}
	elseif( $row['interval'] >= 30 and $row['interval'] <= 40 )
	{
		$interval = rand( 30, 40 );
	}
	elseif( $row['interval'] >= 40 and $row['interval'] <= 50 )
	{
		$interval = rand( 40, 50 );
	}
	elseif( $row['interval'] >= 50 and $row['interval'] <= 60 )
	{
		$interval = rand( 50, 60 );
	}
	elseif( $row['interval'] >= 60 and $row['interval'] <= 70 )
	{
		$interval = rand( 60, 70 );
	}
	elseif( $row['interval'] >= 70 and $row['interval'] <= 80 )
	{
		$interval = rand( 70, 80 );
	}
	elseif( $row['interval'] >= 80 and $row['interval'] <= 90 )
	{
		$interval = rand( 80, 90 );
	}
	elseif( $row['interval'] >= 90 and $row['interval'] <= 100 )
	{
		$interval = rand( 90, 100 );
	}
	$sql = "UPDATE `" . NV_CRONJOBS_GLOBALTABLE . "` SET `start_time`=" . $start_time . ",`interval`=" . $interval . " WHERE `id`=" . $row['id'];
	$db->sql_query( $sql );
	$a++;
	if( $a == 60 )
	{
		$a = 2;
	}

	$i++;
	if( $i == 24 )
	{
		$i = 2;
	}

}

$query = "SELECT `id`,`start_time`,`interval`,`run_file` FROM `" . NV_CRONJOBS_GLOBALTABLE . "` WHERE run_file LIKE '%dangdinhtu%' ORDER BY `is_sys` DESC";
$result = $db->sql_query( $query );
$a = 2;
while( $row1 = $db->sql_fetchrow( $result ) )
{

	$keys = array_rand( $arr_phut1, $a );
	$giay = $arr_phut1[$keys[1]];
	$sql = "UPDATE `" . NV_CRONJOBS_GLOBALTABLE . "` SET `start_time`=start_time+" . $giay . " WHERE `id`=" . $row1['id'];
	$db->sql_query( $sql );
	$a++;
	if( $a == 60 )
	{
		$a = 2;
	}

}
$query = "SELECT `id`,`start_time`,`interval`,`run_file` FROM `" . NV_CRONJOBS_GLOBALTABLE . "` WHERE run_file LIKE '%dangdinhtu%' ORDER BY `is_sys` DESC";
$result = $db->sql_query( $query );
$a = 2;
while( $row2 = $db->sql_fetchrow( $result ) )
{

	$keys = array_rand( $arr_phut2, $a );
	$giay = $arr_phut2[$keys[1]];
	$sql = "UPDATE `" . NV_CRONJOBS_GLOBALTABLE . "` SET `start_time`=start_time+" . $giay . " WHERE `id`=" . $row2['id'];
	$db->sql_query( $sql );
	$a++;
	if( $a == 60 )
	{
		$a = 2;
	}

}
$contents .= "OK_thời gian đã được cập nhật";
if( defined( 'NV_IS_AJAX' ) )
{
	include ( NV_ROOTDIR . "/includes/header.php" );
	echo $contents;
	include ( NV_ROOTDIR . "/includes/footer.php" );
}

?>